import { GpEcsWorld } from "../GpEcsWorld";
import { GpEventDef } from "../GpEventDef";
import { Sglt } from "../SgltDefine";
import ecs, { EcsComponent, EcsEntity, EcsEntityGroup} from "ecs-ts";
import { gg } from "../../../../Game";
export class UiSystem extends ecs.EcsSystem<GpEcsWorld> {
    uiInfo: Sglt.UiInfo
    constructor(world: GpEcsWorld, defaltGroupComps: (new () => EcsComponent)[] = []) {
        super(world, defaltGroupComps);
        this.uiInfo = this.world.getSingleton(Sglt.UiInfo)
    }
    update(): void {
        for (const key in this.uiInfo.createEntityMap) {
            const entity = this.uiInfo.createEntityMap[key]
            gg.eventTarget.emit(GpEventDef.onCreateEcsEntity, entity)

        }
        this.uiInfo.createEntityMap = {}

        for (const key in this.uiInfo.removeEntityMap) {
            const entity = this.uiInfo.removeEntityMap[key]
            gg.eventTarget.emit(GpEventDef.onRemoveEcsEntity, entity)

        }
        this.uiInfo.removeEntityMap = {}
    }
}